#include "ext.h"
#include <linux/ext3_jbd.h>
#include <linux/ext3_fs_sb.h>
#include <linux/buffer_head.h>
#include "header.h"
#define FSNAME(i) i->i_sb->s_type->name
#define IS_EXT3(nm) (!strcmp(nm, "ext3"))
#define IS_EXT4(nm) (!strcmp(nm, "ext4"))

void set_ext3_get_inode_loc(unsigned long addr)
{
        ext3_get_inode_loc_fn = (ext3_get_inode_loc_t) addr;
}

void set_ext4_get_inode_loc(unsigned long addr)
{
        ext4_get_inode_loc_fn = (ext4_get_inode_loc_t) addr;
}

void alloc_block(struct inode* in, sector_t blk_idx, size_t blk_size)
{
        struct buffer_head bh;
        memset(&bh, 0, sizeof(struct buffer_head));
        bh.b_size = blk_size;
        if (IS_EXT3(FSNAME(in))) ext3_get_block_fn(in, blk_idx, &bh, 1);
        else if (IS_EXT4(FSNAME(in))) ext4_get_block_fn(in, blk_idx, &bh, 1);
}

void set_fs_inode_size(struct inode* in, loff_t size)
{
        if (IS_EXT3(FSNAME(in))) EXT3_I(in)->i_disksize = size;
        else if (IS_EXT4(FSNAME(in))) EXT4_I(in)->i_disksize = size;
}

void set_fs_inode_dirty(struct inode* in)
{
        if (in) in->i_sb->s_op->dirty_inode(in);
}
